/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crm.salesOrderProcessing.managedbean;

import commonInfrastructure.accountManagement.entity.SalesmanEntity;
import commonInfrastructure.accountManagement.session.SalesmanSessionBean;
import crm.clientManagement.entity.CompanyEntity;
import frm.creditControl.util.exception.CreditAccountFrozenException;
import frm.creditControl.util.exception.CreditLimitExceededException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpServletRequest;
import mrp.productionPlanning.util.exception.ATPFailedException;
import org.primefaces.event.FlowEvent;
import crm.salesOrderProcessing.entity.DeliveryOrderEntity;
import crm.salesOrderProcessing.entity.LineItemEntity;
import crm.salesOrderProcessing.entity.SalesOrderEntity;
import crm.salesOrderProcessing.entity.SalesQuotationEntity;
import crm.salesOrderProcessing.session.PriceManagementSessionBean;
import crm.salesOrderProcessing.session.ProductManageSessionBean;
import crm.salesOrderProcessing.session.SalesOrderSessionBean;
import crm.salesOrderProcessing.session.SalesQuotationSessionBean;
import crm.salesOrderProcessing.util.exception.PriceUnacceptableException;
import scm.supplyChainManagement.session.DeliveryOrderSessionBean;
import scm.supplyChainManagement.session.InventorySessionBean;
import commonInfrastructure.system.entity.SystemParameterEntity;
import commonInfrastructure.system.session.SystemSessionBean;
import crm.clientManagement.session.AddressSessionBean;
import crm.clientManagement.session.CompanySessionBean;
import crm.salesOrderProcessing.util.exception.IllegalCompanyTypeException;
import frm.creditControl.util.exception.FinanceException;
import mrp.productionPlanning.util.exception.MRPException;

/**
 *
 * @author ReinforceII
 */
@ManagedBean
@ViewScoped
public class CreateNewSalesOrderManagedBean {

    @EJB
    SalesOrderSessionBean salesOrderSessionBean;
    @EJB
    SalesQuotationSessionBean salesQuotationSessionBean;
    @EJB
    DeliveryOrderSessionBean deliveryOrderSessionBean;
    @EJB
    SalesmanSessionBean salesmanSessionBean;
    @EJB
    ProductManageSessionBean productManageSessionBean;
    @EJB
    PriceManagementSessionBean priceManagementSessionBean;
    @EJB
    InventorySessionBean inventorySessionBean;
    @EJB
    SystemSessionBean systemSessionBean;
    @EJB
    CompanySessionBean companySessionBean;
    @EJB
    AddressSessionBean addressSessionBean;
    private SalesOrderEntity salesOrder;
    private DeliveryOrderEntity deliveryOrder;
    private DeliveryOrderEntity selectedDeliveryOrder;
    private SalesQuotationEntity salesQuotation;
    private LineItemEntity lineItem;
    private List<LineItemEntity> salesOrderLineItemList;
    private List<LineItemEntity> deliveryOrderLineItemList;
    private List<DeliveryOrderEntity> deliveryOrderList;
    private SystemParameterEntity systemParameter;
    private List<LineItemEntity> quotationLineItemList;
    private Long productId;
    private Long productId_dOrder;
    private Long deliveryLocationId;
    private Long billingAddressId;
    private CompanyEntity company;
    private static Logger logger = Logger.getLogger(CreateNewSalesOrderManagedBean.class.getName());
    private int amountLeft;
    private int[] amountUsed;

    /** Creates a new instance of CreateNewSalesOrderManagedBean */
    public CreateNewSalesOrderManagedBean() throws IOException {

        lineItem = new LineItemEntity();
        salesOrderLineItemList = new ArrayList<LineItemEntity>();
        deliveryOrderLineItemList = new ArrayList<LineItemEntity>();
        deliveryOrderList = new ArrayList<DeliveryOrderEntity>();
        salesOrder = new SalesOrderEntity();
        deliveryOrder = new DeliveryOrderEntity();
        salesQuotation = getQuotation();
        salesOrder.setStatusId(0);
        company = salesQuotation.getCompany();
        salesOrder.setCustomer(company);
        amountUsed = new int[4];
        for (int i = 0; i < 4; i++) {
            amountUsed[i] = 0;
        }


        quotationLineItemList = salesQuotation.getQuotationLineItems();
    }

    private SalesQuotationEntity getQuotation() {
        if (salesQuotation == null) {
            salesQuotation = (SalesQuotationEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("salesQuotation");
        }
        return salesQuotation;
    }

    private boolean existsInLineItemList(List<LineItemEntity> lineItems, LineItemEntity lineItem) {


        for (LineItemEntity item : lineItems) {

            if (item.getProduct().getId().equals(lineItem.getProduct().getId())) {
                return true;
            }
        }

        return false;
    }

    public void addLineItem(ActionEvent event) {



        lineItem.setProduct(productManageSessionBean.getProductById(productId));

        if (existsInLineItemList(salesOrderLineItemList, lineItem)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "This line item already exists.", ""));
            return;
        }

        boolean flag = false;

        for (LineItemEntity item : getQuotationLineItemList()) {

            if (item.getProduct().getId().equals(productId)) {

                flag = true;
                lineItem.setPrice(item.getPrice());
            }

        }

        if (flag) {
            salesOrderLineItemList.add(lineItem);
            lineItem = new LineItemEntity();
            return;
        }
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Quotation does not contain this product. Please raise a new quotation if you wish to order this product.", ""));
        return;
    }

    public void addLineItemToDeliveryOrder() {

        lineItem.setProduct(productManageSessionBean.getProductById(productId_dOrder));

        if (existsInLineItemList(deliveryOrderLineItemList, lineItem)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "This line item already exists.", ""));
            return;
        }

        boolean flag = false;

        for (LineItemEntity item : salesOrderLineItemList) {

            if (item.getProduct().getId().equals(productId_dOrder)) {
                if (item.getQuantity() < lineItem.getQuantity()) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "The quantity of this line item exceeds its quantity in sales order", ""));
                    return;
                } else {
                    flag = true;
                    lineItem.setPrice(item.getPrice());
                }
            }

        }

        if (flag) {
            deliveryOrderLineItemList.add(lineItem);



            for (LineItemEntity item : salesOrderLineItemList) {

                int i = Integer.valueOf(productId_dOrder.toString()) - 1;

                amountUsed[i] += lineItem.getQuantity();

            }

            lineItem = new LineItemEntity();
        }





    }

    public void deleteLineItem(LineItemEntity lineItem) {

        for (int i = 0; i < salesOrderLineItemList.size(); i++) {

            if (salesOrderLineItemList.get(i).getProduct().getProductName().equals(lineItem.getProduct().getProductName())) {
                salesOrderLineItemList.remove(i);
                break;
            }
        }

    }

    public void deleteLineItem_deliveryOrder(LineItemEntity lineItem) {
        for (int i = 0; i < deliveryOrderLineItemList.size(); i++) {

            if (deliveryOrderLineItemList.get(i).getProduct().getProductName().equals(lineItem.getProduct().getProductName())) {
                deliveryOrderLineItemList.remove(i);

                for (LineItemEntity item : salesOrderLineItemList) {

                    int j = Integer.valueOf(lineItem.getProduct().getId().toString()) - 1;

                    amountUsed[j] -= lineItem.getQuantity();

                }

                break;
            }
        }
    }

    public List<SelectItem> getProductListFromSalesQuotation() { //This is the method that returns a dynimic list of proudcts available in the quotation

        List<SelectItem> selectItems = salesQuotationSessionBean.getProductList(getSalesQuotation());
        return selectItems;
    }

    public List<SelectItem> getProductListFromSalesOrder() { //This is the method that returns a dynimic list of proudcts available in the quotation

        if (salesOrderLineItemList.isEmpty()) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "The sales order is empty", ""));
            return null;
        }
        List<SelectItem> selectItems = new ArrayList<SelectItem>();


        for (LineItemEntity lineItem : salesOrderLineItemList) {

            selectItems.add(new SelectItem(lineItem.getProduct().getId(), lineItem.getProduct().getProductName()));
        }
        return selectItems;
    }

    public List<SelectItem> getShippingAddressList() {

        List<SelectItem> selectItems = companySessionBean.getShippingAddressList(company);
        return selectItems;
    }

    public List<SelectItem> getBillingAddressList() {

        List<SelectItem> selectItems = companySessionBean.getBillingAddressList(company);
        return selectItems;
    }

    public void calculateCumAmount(ActionEvent event) {


        boolean flag = false;

        for (LineItemEntity item : getQuotationLineItemList()) {

            if (item.getProduct().getId().equals(productId)) {

                flag = true;
                lineItem.setPrice(item.getPrice());
            }

        }

        if (flag) {
            lineItem.setCumAmount(priceManagementSessionBean.roundTwoDecimals(lineItem.getPrice() * lineItem.getQuantity()));
            return;
        }

        return;
    }

    public void calculateAmountLeft(ActionEvent event) {

        for (int i = 0; i < 4; i++) {
            Long id = productId_dOrder;

            Long ii = Long.valueOf(i + 1);


            if (id.equals(ii)) {

                for (LineItemEntity item : salesOrderLineItemList) {

                    if (item.getProduct().getId().equals(ii)) {

                        amountLeft = item.getQuantity() - amountUsed[i] - lineItem.getQuantity();

                    }
                }
            }
        }


    }

    public void calculateCumAmountForDeliveryOrder(ActionEvent event) {


        boolean flag = false;

        for (LineItemEntity item : salesOrderLineItemList) {

            if (item.getProduct().getId().equals(productId_dOrder)) {

                flag = true;
                lineItem.setPrice(item.getPrice());
            }

        }

        if (flag) {
            lineItem.setCumAmount(priceManagementSessionBean.roundTwoDecimals(lineItem.getPrice() * lineItem.getQuantity()));
            return;
        }

        return;
    }

    public String onFlowProcess(FlowEvent event) {
        logger.info("Current wizard step:" + event.getOldStep());
        logger.info("Next step:" + event.getNewStep());


        return event.getNewStep();

    }

    public void createSalesOrder(ActionEvent event) throws IOException {

        if (salesOrderLineItemList.isEmpty()) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "The sales order is empty", ""));
            return;
        }


        if (deliveryOrderList.isEmpty()) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "The delivery order is empty", ""));
            return;
        }


        if (!checkIfFullyDelivered()) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "The quantity in delivery order does not match the sales order", ""));
            return;
        }

        double totalAmount = 0;

        systemParameter = systemSessionBean.getSystemParameter();

        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Long salesManId = (Long) request.getSession().getAttribute("userId");
        SalesmanEntity salesman = salesmanSessionBean.getSalesmanById(salesManId);


        salesOrder.setSalesQuotation(getSalesQuotation());

        for (DeliveryOrderEntity dOrder : deliveryOrderList) {

            dOrder.setCIAPayment(salesOrder.isCashInAdvance());
        }



        //set the LineItemEntity
        salesOrder.setSalesOrderLineItems(salesOrderLineItemList);
        for (LineItemEntity item : salesOrderLineItemList) {
            totalAmount = totalAmount + (item.getCumAmount());

        }
        salesOrder.setTotalAmount(totalAmount);




        try {

            priceManagementSessionBean.verifySalesOrderPrice(salesOrder);

        } catch (PriceUnacceptableException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Price unacceptable.", ""));

            return;
        } catch (IllegalCompanyTypeException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Company not found, this shouldn't be happening", ""));

            return;
        }


        salesOrder.setProcessedBy(salesman);
        salesOrder.setStatusId(100);

        salesOrder.setDateCreated(Calendar.getInstance().getTime());
        salesOrder.setDateLastModified(Calendar.getInstance().getTime());

        if (salesOrder.getId() == null) {
            salesOrderSessionBean.addSalesOrder(salesOrder);
            salesQuotation.setUsed(true);
            salesQuotationSessionBean.saveChanges(salesQuotation);
        } else {
            salesOrderSessionBean.saveChanges(salesOrder);
        }



        if (totalAmount < systemParameter.getLargeOrderAmount()) {
            salesOrder.setStatusId(200);
        }


        if (salesOrder.getStatusId() == 200) {
            try {

                salesOrderSessionBean.verifySalesOrder(salesOrder);

            } catch (CreditAccountFrozenException e) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Credit account is frozen. Please pay outstnading bills.", ""));

                return;
            } catch (CreditLimitExceededException e) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No enough credit. Please reduce amount ordered or pay cash in advance.", ""));

                return;
            } catch (ATPFailedException e) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "ATP failed: " + e.getMessage(), ""));
                salesOrder.setStatusId(300);
                salesOrder.setDateLastModified(Calendar.getInstance().getTime());
                salesOrderSessionBean.saveChanges(salesOrder);

                return;
            } catch (FinanceException e) {

                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Unknown finance error.", ""));

                return;
            } catch (MRPException e) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Unknown MRP error.", ""));

                return;
            }
            salesOrder.setStatusId(400);
            salesOrder.setChildDeliveryOrders(deliveryOrderList);
//            inventorySessionBean.reserveInventory(salesOrder);
        }
        //generate the deliveryOrder at here;

        salesOrder.setDateLastModified(Calendar.getInstance().getTime());

        salesOrderSessionBean.saveChanges(salesOrder);


        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("lastURL", "createSalesOrder");
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("salesOrder", salesOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("salesOrderCreationResult.xhtml");

        return;

    }

    public void saveDraft(ActionEvent event) throws IOException {

        systemParameter = systemSessionBean.getSystemParameter();
        salesOrder.setSalesOrderLineItems(salesOrderLineItemList);
        salesOrder.setChildDeliveryOrders(deliveryOrderList);



        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Long salesManId = (Long) request.getSession().getAttribute("userId");
        SalesmanEntity salesman = salesmanSessionBean.getSalesmanById(salesManId);


        salesOrder.setSalesQuotation(getSalesQuotation());


        double totalAmount = 0;


        for (LineItemEntity item : salesOrderLineItemList) {
            totalAmount = totalAmount + (item.getCumAmount());

        }
        salesOrder.setTotalAmount(totalAmount);


        salesOrder.setDateCreated(Calendar.getInstance().getTime());

        salesOrder.setProcessedBy(salesman);
        salesOrder.setStatusId(50);
        if (salesOrder.getId() == null) {
            salesOrderSessionBean.addSalesOrder(salesOrder);

            salesQuotation.setUsed(true);
            salesQuotationSessionBean.saveChanges(salesQuotation);
        } else {
            salesOrderSessionBean.saveChanges(salesOrder);
        }
        salesOrder.setDateLastModified(Calendar.getInstance().getTime());

        salesOrderSessionBean.saveChanges(salesOrder);


        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("lastURL", "createSalesOrder");
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("salesOrder", salesOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("salesOrderDraftSaved.xhtml");

        return;
    }

    public void verifyPrice(ActionEvent event) {


        if (salesOrderLineItemList.isEmpty()) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "The sales order is empty", ""));
            return;
        }
        double totalAmount = 0;
        salesOrder.setSalesOrderLineItems(salesOrderLineItemList);
        for (LineItemEntity item : salesOrderLineItemList) {
            totalAmount = totalAmount + (item.getCumAmount());

        }
        salesOrder.setTotalAmount(totalAmount);
        try {

            priceManagementSessionBean.verifySalesOrderPrice(salesOrder);

        } catch (PriceUnacceptableException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Price unacceptable.", ""));

            return;
        } catch (IllegalCompanyTypeException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Company not found, this shouldn't be happening", ""));

            return;
        }

        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Price verified, please proceed to the next page.", ""));

    }

    private boolean checkIfFullyDelivered() {

        int[] amount = new int[4];

        for (LineItemEntity item : salesOrderLineItemList) {

            int i = Integer.valueOf(item.getProduct().getId().toString()) - 1;

            amount[i] = item.getQuantity();

        }

        for (DeliveryOrderEntity deliveryOrder : deliveryOrderList) {
            for (LineItemEntity item : deliveryOrder.getLineItems()) {
                int i = Integer.valueOf(item.getProduct().getId().toString()) - 1;

                amount[i] = amount[i] - item.getQuantity();
            }
        }

        for (int i = 0; i < 4; i++) {

            if (amount[i] != 0) {
                return false;
            }
        }


        return true;
    }

    public void addDeliveryOrder(ActionEvent event) {
        int a = deliveryOrderSessionBean.getAllDeliveryOrders().size() + deliveryOrderList.size() + 1;
        Long idNumber = Long.valueOf(a);
        deliveryOrder.setId(idNumber);

        deliveryOrder.setLineItems(deliveryOrderLineItemList);
        deliveryOrder.setGenerateDate(Calendar.getInstance().getTime());
        deliveryOrder.setParentSalesOrder(salesOrder);
        deliveryOrder.setShippingAddress(addressSessionBean.getAddressById(deliveryLocationId));
        deliveryOrder.setBillingAddress(addressSessionBean.getAddressById(billingAddressId));


        if (existsInDeliveryOrderList(deliveryOrder)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "There is a delivery order of the same time and address in the delivery order list.", ""));
            return;
        }

        deliveryOrderList.add(deliveryOrder);

        deliveryOrder = new DeliveryOrderEntity();

        deliveryOrderLineItemList = new ArrayList<LineItemEntity>();

    }

    private boolean existsInDeliveryOrderList(DeliveryOrderEntity deliveryOrder) {

        boolean timeExists = false;
        boolean locationExists = false;

        for (DeliveryOrderEntity dOrder : deliveryOrderList) {

            if (deliveryOrder.getDeliveryDate().equals(dOrder.getDeliveryDate())) {
                timeExists = true;
            }
            if (deliveryOrder.getShippingAddress().equals(dOrder.getShippingAddress())) {
                locationExists = true;
            }
            if (timeExists && locationExists) {
                return true;
            }
        }

        return (timeExists && locationExists);
    }

    public List<LineItemEntity> getDeliveryOrderLineItems() {

        List<LineItemEntity> listOfLineItems = new ArrayList<LineItemEntity>();
        if (deliveryOrderList.isEmpty()) {
            return null;
        } else {

            for (int i = 0; i < deliveryOrderList.size(); i++) {
                if (deliveryOrderList.get(i).getId() == selectedDeliveryOrder.getId()) {

                    listOfLineItems = deliveryOrderList.get(i).getLineItems();
                    break;

                }
            }
            return listOfLineItems;

        }
    }

    public void deleteDeliveryrder(DeliveryOrderEntity choosenDeliveryOrder) {
        for (int i = 0; i < deliveryOrderList.size(); i++) {

            if (deliveryOrderList.get(i).getId().equals(choosenDeliveryOrder.getId())) {
                deliveryOrderList.remove(i);

                for (LineItemEntity lItem : choosenDeliveryOrder.getLineItems()) {

                    for (LineItemEntity item : salesOrderLineItemList) {

                        int j = Integer.valueOf(lItem.getProduct().getId().toString()) - 1;

                        amountUsed[j] -= lItem.getQuantity();

                    }
                }

                break;
            }
        }
    }

    /**
     * @return the salesOrder
     */
    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    /**
     * @param salesOrder the salesOrder to set
     */
    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    /**
     * @return the salesQuotation
     */
    public SalesQuotationEntity getSalesQuotation() {
        return salesQuotation;
    }

    /**
     * @param salesQuotation the salesQuotation to set
     */
    public void setSalesQuotation(SalesQuotationEntity salesQuotation) {
        this.salesQuotation = salesQuotation;
    }

    /**
     * @return the lineItem
     */
    public LineItemEntity getLineItem() {
        return lineItem;
    }

    /**
     * @param lineItem the lineItem to set
     */
    public void setLineItem(LineItemEntity lineItem) {
        this.lineItem = lineItem;
    }

    /**
     * @return the salesOrderLineItemList
     */
    public List<LineItemEntity> getSalesOrderLineItemList() {
        return salesOrderLineItemList;
    }

    /**
     * @param salesOrderLineItemList the salesOrderLineItemList to set
     */
    public void setSalesOrderLineItemList(List<LineItemEntity> lineItemList) {
        this.salesOrderLineItemList = lineItemList;
    }

    /**
     * @return the systemParameter
     */
    public SystemParameterEntity getSystemParameter() {
        return systemParameter;
    }

    /**
     * @param systemParameter the systemParameter to set
     */
    public void setSystemParameter(SystemParameterEntity systemParameter) {
        this.systemParameter = systemParameter;
    }

    /**
     * @return the quotationLineItemList
     */
    public List<LineItemEntity> getQuotationLineItemList() {
        return quotationLineItemList;
    }

    /**
     * @param quotationLineItemList the quotationLineItemList to set
     */
    public void setQuotationLineItemList(List<LineItemEntity> quotationLineItemList) {
        this.setQuotationLineItemList(quotationLineItemList);
    }

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public DeliveryOrderEntity getDeliveryOrder() {
        return deliveryOrder;
    }

    public void setDeliveryOrder(DeliveryOrderEntity deliveryOrder) {
        this.deliveryOrder = deliveryOrder;
    }

    public List<DeliveryOrderEntity> getDeliveryOrderList() {
        return deliveryOrderList;
    }

    public void setDeliveryOrderList(List<DeliveryOrderEntity> deliveryOrderList) {
        this.deliveryOrderList = deliveryOrderList;
    }

    public List<LineItemEntity> getDeliveryOrderLineItemList() {
        return deliveryOrderLineItemList;
    }

    public void setDeliveryOrderLineItemList(List<LineItemEntity> deliveryOrderLineItemList) {
        this.deliveryOrderLineItemList = deliveryOrderLineItemList;
    }

    public Long getProductId_dOrder() {
        return productId_dOrder;
    }

    public void setProductId_dOrder(Long productId_dOrder) {
        this.productId_dOrder = productId_dOrder;
    }

    /**
     * @return the deliveryLocationId
     */
    public Long getDeliveryLocationId() {
        return deliveryLocationId;
    }

    /**
     * @param deliveryLocationId the deliveryLocationId to set
     */
    public void setDeliveryLocationId(Long deliveryLocationId) {
        this.deliveryLocationId = deliveryLocationId;
    }

    /**
     * @return the billingAddressId
     */
    public Long getBillingAddressId() {
        return billingAddressId;
    }

    /**
     * @param billingAddressId the billingAddressId to set
     */
    public void setBillingAddressId(Long billingAddressId) {
        this.billingAddressId = billingAddressId;
    }

    /**
     * @return the amountLeft
     */
    public int getAmountLeft() {
        return amountLeft;
    }

    public DeliveryOrderEntity getSelectedDeliveryOrder() {
        return selectedDeliveryOrder;
    }

    public void setSelectedDeliveryOrder(DeliveryOrderEntity selectedDeliveryOrder) {
        this.selectedDeliveryOrder = selectedDeliveryOrder;
    }
}
